package org.example.secondkill.response;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.ToString;

@Data
@ToString
@AllArgsConstructor
public class BaseResponse<T> {
    private int code;
    private String msg;
    private T data;

    public BaseResponse(ResultCode resultCode) {
        this.code = resultCode.getCode();
        this.msg = resultCode.getMsg();
    }

    public static <T> BaseResponse<T> success() {
        return new BaseResponse<>(ResultCode.SUCCESS);
    }

    public static <T> BaseResponse<T> success(T data) {
        BaseResponse<T> response = new BaseResponse<>(ResultCode.SUCCESS);
        response.setData(data);
        return response;
    }

    public static <T> BaseResponse<T> error(ResultCode resultCode) {
        return new BaseResponse<>(resultCode);
    }
}
